from selenium import webdriver
from selenium.webdriver import ActionChains
import time

# 建立浏览器实例
browser = webdriver.Chrome()
# 打开网址
browser.get('http://localhost:8080/exam_login')
# 获取用户名输入框
input_kuang = browser.find_element_by_xpath('//*[@id="app"]/div/section/div/div[1]/input')
input_kuang.send_keys('wangwang')
time.sleep(1)
# 获取密码输入框
input_kuang = browser.find_element_by_xpath('//*[@id="app"]/div/section/div/div[2]/input')
input_kuang.send_keys('123')
action = ActionChains(browser)
# 找到拖动对象
button = browser.find_element_by_class_name('dv_handler')
box = browser.find_element_by_class_name('dv_text')
# 获取按钮长度
square_len = button.size.get('width')
# 获取滚动条长度
box_len = box.size.get('width')
print(square_len)
print(box_len)
# 定义动作对象
action = ActionChains(browser)
# 定义动作类型
action.click_and_hold(button).perform()
# 释放动作
action.reset_actions()
# 拖动距离
action.move_by_offset((box_len - square_len), 0).perform()
# 点击登录按钮
browser.find_element_by_class_name('h-btn').click()
time.sleep(10)
browser.close()
